<template>
  <div class="AuthenticatedUser">
    <div class="searchBox">
      <el-input placeholder="请输入内容" v-model="id">
        <template slot="prepend">ID</template>
      </el-input>
      <el-input placeholder="请输入内容" v-model="phone">
        <template slot="prepend">手机号</template>
      </el-input>
      <el-date-picker
        v-model="timeArr"
        type="daterange"
        align="right"
        unlink-panels
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        :picker-options="timeOptions"
        value-format="yyyy-MM-dd"
        @change="focus"
      >
      </el-date-picker>
      <el-button style="margin-left: 10px" @click="search" class="btn"
        >搜索</el-button
      >
    </div>
    <el-radio-group v-model="type" @change="search" fill="#7b94d8">
      <el-radio-button label="0">未审核</el-radio-button>
      <el-radio-button label="1">已审核</el-radio-button>
    </el-radio-group>
    <el-card>
      <el-radio-group
        size="small"
        v-model="sex"
        @change="search"
        fill="#7b94d8"
      >
        <el-radio-button label="1">男用户</el-radio-button>
        <el-radio-button label="2">女用户</el-radio-button>
      </el-radio-group>
      <el-table
        v-loading="loading"
        :data="tableData"
        style="width: 100%; margin-top: 10px"
        :header-cell-style="{ background: '#f5f7fa' }"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" label="全选" width="55">
        </el-table-column>
        <el-table-column prop="user_id" label="ID" width="70">
        </el-table-column>
        <el-table-column prop="headimg" label="头像" width="70">
          <template slot-scope="scope">
            <el-image
              style="width: 50px; height: 50px; border-radius: 5px"
              :src="scope.row.headimg"
              :preview-src-list="[scope.row.headimg]"
            >
            </el-image>
          </template>
        </el-table-column>
        <el-table-column prop="voice_sign" label="语音标签">
          <template slot-scope="scope">
            <audio
              controls
              style="width: 100px; height: 40px"
              :src="scope.row.voice_sign"
            >
              不支持
            </audio>
          </template>
        </el-table-column>
        <el-table-column prop="full_name" label="真实姓名"> </el-table-column>
        <el-table-column prop="id_number" label="身份证号码"> </el-table-column>
        <el-table-column prop="medio" label="身份证照片">
          <template slot-scope="scope">
            <el-image
              style="width: 50px; height: 50px; border-radius: 5px"
              :src="scope.row.just_img"
              :preview-src-list="[scope.row.just_img]"
            >
            </el-image>
            <el-image
              style="
                width: 50px;
                height: 50px;
                border-radius: 5px;
                margin-left: 20px;
              "
              :src="scope.row.back_img"
              :preview-src-list="[scope.row.back_img]"
            >
            </el-image>
          </template>
        </el-table-column>
        <el-table-column prop="phone" label="联系电话"> </el-table-column>
        <el-table-column prop="is_exit" label="已有此身份证">
          <!-- <template slot-scope="scope">
            {{ scope.row.repeat_idCard == 1 ? "否" : "是" }}
          </template> -->
        </el-table-column>
        <el-table-column
          v-if="type == 1"
          key="232"
          prop="author_type"
          label="主播类型"
        >
          <template slot-scope="scope">
            {{
              scope.row.author_type == 1
                ? "认证主播"
                : scope.row.author_type == 2
                ? "工会主播"
                : scope.row.author_type == 3
                ? "平台合作主播"
                : ""
            }}
          </template>
        </el-table-column>
        <el-table-column label="审核状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.state == 0">未审核</el-tag>
            <el-tag type="success" v-if="scope.row.state == 1">审核通过</el-tag>
            <el-tag type="danger" v-if="scope.row.state == 2">审核驳回</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          v-if="type == 1"
          key="2322"
          prop="reasons"
          label="驳回原因"
        >
        </el-table-column>
        <el-table-column
          prop="medio"
          label="操作"
          v-if="type == 0"
          key="231322"
        >
          <template slot-scope="scope">
            <el-button
              type="info"
              size="mini"
              @click="nopass(scope.row.id)"
              plain
              >驳 回</el-button
            >
            <el-button
              type="success"
              size="mini"
              @click="pass(scope.row.id)"
              plain
              >通 过</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-button
        type="primary"
        style="margin: 10px"
        size="small"
        @click="plpass"
        :disabled="!sex"
        plain
        >批量通过</el-button
      >
      <pagination
        :total="total"
        :page.sync="page"
        :limit.sync="pageSize"
        @pagination="getList"
      />
    </el-card>
    <!-- 驳回 -->
    <el-dialog title="驳回请求" :visible.sync="dialogVisible" width="30%">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="驳回理由">
          <el-radio-group
            v-model="form.quick"
            @change="form.reason = form.quick"
          >
            <el-radio label="头像不清晰">头像不清晰</el-radio>
            <el-radio label="语音不清晰">语音不清晰</el-radio>
            <el-radio label="身份证复用">身份证复用</el-radio>
            <el-radio label="身份证图片不清晰">身份证图片不清晰</el-radio>
            <el-radio label="">手动输入理由</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-show="!form.quick" label="">
          <el-input placeholder="请输入理由" v-model="form.reason"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitNopass">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 通过 -->
    <el-dialog title="主播划分" :visible.sync="dialogVisible1" width="30%">
      <el-form ref="form1" :model="form1" label-width="80px">
        <el-form-item label="主播分类">
          <el-radio-group v-model="form1.type">
            <el-radio label="1">认证主播</el-radio>
            <el-radio label="2">工会主播</el-radio>
            <el-radio label="3">平台合作主播</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="主播标签">
          <el-select v-model="form1.lable" placeholder="请选择">
            <el-option
              v-for="item in lableOptions"
              :key="item.id"
              :label="item.title"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-show="form1.type == 2" label="所属工会">
          <el-select
            v-model="form1.union"
            filterable
            placeholder="请选择或输入"
          >
            <el-option
              v-for="item in unionOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible1 = false">取 消</el-button>
        <el-button type="primary" @click="submitPass">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination"; // 分页
import {
  AttestationUserList,
  AttestationUserVerifyAuth,
} from "@/api/AuditManagement";
export default {
  components: { Pagination },

  data() {
    return {
      loading: false,
      value: "",
      phone: "",
      id: "",
      sex: "1",
      type: "0",
      timeArr: [],
      startTime: "",
      endTime: "",
      timeOptions: {
        disabledDate(platformValue) {
          return platformValue.getTime() > Date.now() - 8.64e6;
        },
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 6);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      tableData: [],
      total: 0,
      page: 1,
      pageSize: 10,
      targetArr: [],
      targetId: "",
      dialogVisible: false,
      form: {
        quick: "1",
        reason: "",
      },
      dialogVisible1: false,
      form1: {
        type: "1",
        union: "",
        lable: "",
      },
      unionOptions: [],
      lableOption: [],
      lableOptions: [],
    };
  },
  methods: {
    search() {
      this.page = 1;
      this.getList();
    },
    focus() {
      if (!this.timeArr) {
        this.timeArr = [];
      }
      this.startTime = this.timeArr[0];
      this.endTime = this.timeArr[1];
    },
    handleSelectionChange(arr) {
      this.targetArr = arr;
    },
    async getList() {
      const res = await AttestationUserList({
        state: this.type,
        sex: this.sex,
        page: this.page,
        pageSize: this.pageSize,
        phone: this.phone,
        startTime: this.startTime,
        endTime: this.endTime,
        id_code: this.id,
      });
      if (res.code == 0) {
        this.tableData = res.data.list;
        this.total = parseInt(res.data.count);
        this.unionOptions = res.data.unionInfo;
        this.lableOption = res.data.lableInfo;
      }
    },
    nopass(id) {
      this.targetId = id;
      this.form = {
        quick: "1",
        reason: "",
      };
      this.dialogVisible = true;
    },
    pass(id) {
      this.targetId = id;
      if (this.sex == 1) {
        this.lableOptions = this.lableOption.map((item) => {
          return {
            id: item.id,
            title: item.man_title,
          };
        });
      } else {
        this.lableOptions = this.lableOption.map((item) => {
          return {
            id: item.id,
            title: item.women_title,
          };
        });
      }
      this.form1 = {
        type: "1",
        union: "",
        lable: "",
      };
      this.dialogVisible1 = true;
    },
    plpass() {
      let id = this.targetArr.map((item) => {
        return item.id;
      });
      this.pass(id);
    },
    async submitNopass() {
      if (!this.form.reason) {
        return this.$message.error("请选择理由！");
      }
      const res = await AttestationUserVerifyAuth({
        id: this.targetId,
        state: "2",
        reasons: this.form.reason,
      });
      if (res.code == 0) {
        this.$message.success("操作成功！");
        this.dialogVisible = false;
        this.getList();
      }
    },
    async submitPass() {
      const res = await AttestationUserVerifyAuth({
        id: this.targetId,
        state: "1",
        author_type: this.form1.type,
        lable_id: this.form1.lable,
        union_id: this.form1.union,
      });
      if (res.code == 0) {
        this.$message.success("操作成功！");
        this.dialogVisible = false;
        this.getList();
        this.dialogVisible1 = false;
      }
    },
  },
  created() {
    this.getList();
  },
};
</script>

<style lang="less" scoped>
.AuthenticatedUser {
  padding: 20px;
  .searchBox {
    margin-bottom: 20px;
    .el-input {
      width: 300px;
      margin-right: 10px;
    }
  }
  .el-radio {
    margin-bottom: 10px;
  }
}
</style>